package com.frxuexi.lib_base

import android.content.Context
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.annotation.Interceptor
import com.alibaba.android.arouter.facade.callback.InterceptorCallback
import com.alibaba.android.arouter.facade.template.IInterceptor
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
import java.lang.RuntimeException

@Interceptor(priority = 1, name = "登录拦截")
class LoginInterceptor:IInterceptor {
    override fun init(context: Context?) {

    }

    override fun process(postcard: Postcard?, callback: InterceptorCallback?) {
        if(arrayOf("/app/LoginActivity","/app/RegisterActivity","/soufang/HourseDetailActivity","/soufang/HoursescActivity","/video/SearchActivity"
        ,"/video/SearchActivity").contains(postcard?.path)  || !SPUtils.getInstance().getString("token","").isNullOrEmpty()){
            callback?.onContinue(postcard)
        }else{
            callback?.onInterrupt(RuntimeException("登录拦截"))
            ARouter.getInstance().build("/app/LoginActivity").navigation()
        }
    }
}